package org.cuit.lmq.constants.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.cuit.lmq.exception.CustomException;

import java.util.Arrays;

/**
 * @author Seon
 * @date 2023/3/3
 */
@Getter
@AllArgsConstructor
public enum TrainTypeEnum {
    RUNNING("running", "跑步"),
    ROPE_SKIPPING("skip", "跳绳"),
    TABLE_TENNIS("ping_pang", "乒乓球专项");

    private String type;
    private String name;
    public final static String TYPE_NULL = "训练类型不能为空";
    public final static String TYPE_NOT_EXIST = "训练类型参数不存在";



    public static TrainTypeEnum isExist(String type) {
        if (StringUtils.isBlank(type)) {
            throw new CustomException(TYPE_NULL);
        }
        return Arrays.stream(TrainTypeEnum.values())
                .filter(typeEnum -> typeEnum.getType().equals(type))
                .findFirst()
                .orElseThrow(() -> new CustomException(TYPE_NOT_EXIST));
        //todo:回去熟悉一下这个东西。
    }

}
